﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ThuVien;

namespace TranTekBE
{
    public partial class Default : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Page.IsPostBack == false)
            {
                txtUserName.Text = FunctionsUtils.GetConfigValue("UserNameLogin");
            }
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            ltLoginErr.Text = string.Empty;

            bool bResult = this.CheckDataLogin();

            if (bResult == false)
                return;

            //string sPassword = (txtPassword.Text.Trim().Length > 0 ? FunctionsUtils.EncryptNonDecrypt(txtPassword.Text, HashAlgorithmMode.md5) : string.Empty);

            //connect db
            if ((txtUserName.Text.ToLower().Equals(FunctionsUtils.GetConfigValue("UserNameLogin")) == false) || (txtPassword.Text.ToLower().Equals(FunctionsUtils.GetConfigValue("PasswordLogin")) == false))
            {
                ltLoginErr.Text = FunctionsUtils.Msg["frm_NotLogin"];
            }
            else
            {
                User user = new User();
                user.UserISN = 1;
                this.UserInfo = user;
                Response.Redirect("CategoryMgmt.aspx", true);
            }
        }

        private bool CheckDataLogin()
        {
            bool bResult = true;

            if (txtUserName.Text.Trim().Length == 0)
            {
                FunctionsUtils.ShowSmallError(ltUserNameErr, FunctionsUtils.Msg["frm_Required"]);
                bResult = false;
            }
            /*
            if (txtPassword.Text.Trim().Length == 0)
            {
                FunctionsUtils.ShowSmallError(ltPasswordErr, FunctionsUtils.Msg["frm_Required"]);
                bResult = false;
            }
            */
            return bResult;
        }
    }
}
